﻿using System;
using System.Collections.Generic;
using System.IO;
using System.IO.IsolatedStorage;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BKDict.Data_Access
{
    class Recently
    {
        public string filename = "recently.txt";
        //Write to favorite file
        public bool Write(string content)
        {
            try
            {
                IsolatedStorageFile ISF = IsolatedStorageFile.GetUserStoreForApplication();

                using (StreamWriter sw = new StreamWriter(new IsolatedStorageFileStream(filename, FileMode.Append, FileAccess.Write, ISF)))
                {
                    sw.WriteLine(content);

                }
                return true;
            }
            catch (Exception) { return false; }
        }

        public List<string> GetList()
        {
            List<string> lstKey = new List<string>();
            try
            {
                IsolatedStorageFile ISF = IsolatedStorageFile.GetUserStoreForApplication();
                IsolatedStorageFileStream fs = ISF.OpenFile(filename, FileMode.OpenOrCreate, FileAccess.Read);
                using (StreamReader sr = new StreamReader(fs))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        if (line != "")
                            lstKey.Add(line);
                    }
                }
                return lstKey;
            }
            catch (Exception) { return null; }
        }
    }
}
